package view;

import java.awt.Color;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;

import model.core.utente.Studente;

/**
 * 
 * @author Giuseppe Fusco (fusgius19@gmail.com)
 *
 */
@SuppressWarnings("rawtypes")
public class StudenteCellRenderer extends JTextField implements ListCellRenderer {

	/**
	 * 
	 */

	private static final long serialVersionUID = 3652481109806536780L;
	private List<Integer> is;
	
	public StudenteCellRenderer(List<Integer> vt){
		setOpaque(true);
		this.is = vt;
		if(vt==null)
			is = new ArrayList<Integer>();
	}
	
	public StudenteCellRenderer(){
		setOpaque(true);
		this.is = new ArrayList<Integer>();
	}
	

	@Override
	public Component getListCellRendererComponent(JList arg0,
			Object arg1, int arg2, boolean arg3, boolean arg4) {
		// TODO Auto-generated method stub
		
		Studente g = (Studente) arg1;
		this.setFont(arg0.getFont());
		this.setText(g.getNome()+"\t"+g.getCognome()+"\t"+g.getMatricola());
		if (arg3) {
			this.setBackground(arg0.getSelectionBackground());
			this.setForeground(arg0.getSelectionForeground());
		} else {
			this.setBackground(arg0.getBackground());
			this.setForeground(arg0.getForeground());
		}
		
		for(Integer i: is){
			if(i.intValue()==arg2)
				{
				setBackground(Color.ORANGE);
//				setForeground(Color.RED);
				}
		}
		return this;
	}
	

}
